home *** CD-ROM | disk | FTP | other *** search
/ Aminet 33 / Aminet 33 - October 1999.iso / Aminet / dev / cross / avra-0.4_src.lha / avra-0.4 / stdextra.c < prev    next >
Encoding:
C/C++ Source or Header  |  1999-01-28  |  2.4 KB  |  145 lines

  1. /********************************************************************
  2.  * Extra standard functions
  3.  */
  4.  
  5. #include <stdio.h>
  6. #include <ctype.h>
  7.  
  8. #include "misc.h"
  9.  
  10.  
  11. /********************************************************************
  12.  * Case insensetive strcmp()
  13.  */
  14.  
  15. int nocase_strcmp(char *s, char *t)
  16.     {
  17.     int i;
  18.  
  19.     for(i = 0; tolower(s[i]) == tolower(t[i]); i++)
  20.         if(s[i] == '\0')
  21.             return(0);
  22.     return(tolower(s[i]) - tolower(t[i]));
  23.     }
  24.  
  25.  
  26. /********************************************************************
  27.  * Case insensetive strncmp()
  28.  */
  29.  
  30. int nocase_strncmp(char *s, char *t, int n)
  31.     {
  32.     int i;
  33.  
  34.     for(i = 0; (tolower(s[i]) == tolower(t[i])); i++, n--)
  35.         if((s[i] == '\0') || (n == 1))
  36.             return(0);
  37.     return(tolower(s[i]) - tolower(t[i]));
  38.     }
  39.  
  40.  
  41. /********************************************************************
  42.  * Case insensetive strstr()
  43.  */
  44.  
  45. char *nocase_strstr(char *s, char *t)
  46.     {
  47.     int i = 0, j, found = False;
  48.  
  49.     while((s[i] != '\0') && !found)
  50.         {
  51.         j = 0;
  52.         while(tolower(t[j]) == tolower(s[i + j]))
  53.             {
  54.             j++;
  55.             if(t[j] == '\0')
  56.                 {
  57.                 found = True;
  58.                 break;
  59.                 }
  60.             else if(s[i + j] == '\0')
  61.                 break;
  62.             }
  63.         i++;
  64.         }
  65.     i--;
  66.     if(found)
  67.         return(&s[i]);
  68.     return(NULL);
  69.     }
  70.  
  71.  
  72. /********************************************************************
  73.  * ascii to hex
  74.  * ignores "0x"
  75.  */
  76.  
  77. int atox(char *s)
  78.     {
  79.     int i = 0, ret = 0;
  80.  
  81.     while(s[i] != '\0')
  82.         {
  83.         ret <<= 4;
  84.         if((s[i] <= 'F') && (s[i] >= 'A'))
  85.             ret |= s[i] - 'A' + 10;
  86.         else if((s[i] <= 'f') && (s[i] >= 'a'))
  87.             ret |= s[i] - 'a' + 10;
  88.         else if((s[i] <= '9') && (s[i] >= '0'))
  89.             ret |= s[i] - '0';
  90.         i++;
  91.         }
  92.     return(ret);
  93.     }
  94.  
  95.  
  96. /********************************************************************
  97.  * n ascii chars to int
  98.  */
  99.  
  100. int atoi_n(char *s, int n)
  101.     {
  102.     int i = 0, ret = 0;
  103.  
  104.     while((s[i] != '\0') && n)
  105.         {
  106.         ret = 10 * ret + (s[i] - '0');
  107.         i++;
  108.         n--;
  109.         }
  110.     return(ret);
  111.     }
  112.  
  113.  
  114. /********************************************************************
  115.  * n ascii chars to hex
  116.  * 0 < n <= 8
  117.  * ignores "0x"
  118.  */
  119.  
  120. int atox_n(char *s, int n)
  121.     {
  122.     int i = 0, ret = 0;
  123.  
  124.     while((s[i] != '\0') && n)
  125.         {
  126.         ret <<= 4;
  127.         if((s[i] <= 'F') && (s[i] >= 'A'))
  128.             ret |= s[i] - 'A' + 10;
  129.         else if((s[i] <= 'f') && (s[i] >= 'a'))
  130.             ret |= s[i] - 'a' + 10;
  131.         else if((s[i] <= '9') && (s[i] >= '0'))
  132.             ret |= s[i] - '0';
  133.         i++;
  134.         n--;
  135.         }
  136.     return(ret);
  137.     }
  138.  
  139.  
  140.  
  141.  
  142.  
  143.  
  144.  
  145.